package org.example.cmsvue.utils;

import lombok.Data;
import org.example.cmsvue.enums.Renum;


/**
 * @version V1.0
 * @Package com.ss.jwt.R
 * @author: Liu
 * @Date: 10:21
 */
@Data
public class R<T> {
    /*返回体*/
    private Integer code;
    private String msg;
    private T data;

    /*成功，且返回体有数据*/
    public static R success(Object object) {
        R r = new R();
        r.setCode(Renum.SUCCESS.getCode());
        r.setMsg(Renum.SUCCESS.getMsg());
        r.setData(object);
        return r;
    }

    //成功，但返回体没数据
    public static R success() {
        return success(null);
    }

    //失败返回信息
    public static R fail(Integer code, String msg) {
        R r = new R();
        r.setCode(code);
        r.setMsg(msg);
        return r;
    }

    public static R fail(String msg) {
        R r = new R();
        r.setCode(400);
        r.setMsg(msg);
        return r;
    }

}
